//==调试HSE管理==调试HSE管理===会议
<template>
  <PageTemplate>
    <div class="sri-process" slot="content">
      <el-form
        inline
        :model="query"
        ref="query"
        label-position="right"
        label-width="82px"
        class="search-collapse-pro-form"
      >
        <SearchCollapsePro :isAdvSearch="false">
          <div slot="title" class="search-collapse-pro-title">
            <el-form-item label-width="0px">
              <el-input v-model="query.trial" :placeholder="$t('she.meeting_trial')">
                <el-button slot="append" icon="el-icon-search" @click="queryDataTableLike"></el-button>
              </el-input>
            </el-form-item>
          </div>
          <div slot="collapse">
            <!-- 高级搜索具体内容 -->

            <!-- 查询和重置按钮-->
            <el-row :gutter="10">
              <div class="btn-group-search">
                <el-col :span="2">&nbsp;</el-col>
                <el-col :span="6">
                  <el-button
                    type="primary"
                    class="btn-default"
                    @click="getAllDataTable"
                    size="small"
                  >{{$t('cm.query')}}</el-button>
                  <el-button
                    class="btn-second"
                    @click="queryReset('query')"
                    style="margin:0;"
                    size="small"
                  >{{$t('cm.reset')}}</el-button>
                </el-col>
              </div>
            </el-row>
          </div>
        </SearchCollapsePro>
      </el-form>
      <el-row class="row-empty-20"></el-row>
      <PageTableCollapse :collapseStatus="true">
        <el-row slot="title">
          <!-- <el-col :span="12"><div style="line-height: 40px"> {{$t('sri.table_title')}} </div></el-col> -->
          <el-col>
            <!-- style="float:right;" -->
            <div>
              <!-- <el-button type="primary" @click="add">
                <i class="el-icon-edit"></i> {{$t('cm.add')}}
              </el-button> -->
              <!-- <el-button type="primary" @click="edit2">
                <i class="el-icon-edit"></i> {{$t('cm.edit')}}
              </el-button>
              <el-button type="primary" @click="exportOp">
                <i class="el-icon-export"></i> {{$t('cm.export')}}
              </el-button> -->
              <el-button type="primary" @click="editgongqian" v-if="showBtn">
                <i class="el-icon-edit"></i> {{$t('cm.addsheworking')}}
              </el-button>
              <el-button type="primary" @click="editbanqian" v-if="showBtn">
                <i class="el-icon-edit"></i> {{$t('cm.addshemetting')}}
              </el-button>
              <el-button type="primary" @click="del" v-if="showBtn && isSys ==='true'">
                <i class="el-icon-delete"></i> {{$t('cm.delete')}}
              </el-button>
            </div>
          </el-col>
        </el-row>
        <el-table
          class="table"
          border
          ref="multipleTable"
          :data="tables"
          tooltip-effect="dark"
          style="width: 100%"
          :show-overflow-tooltip="true"
          @selection-change="handleSelectionChange"
          :header-cell-style="{background:tableHeaderBGC}"
          @sort-change="sortMethod"
        >
          <el-table-column align="center" type="selection" width="60"></el-table-column>
          <el-table-column type="index" :label="$t('cm.no')" align="center" width="60"></el-table-column>
          <el-table-column prop="trial" :label="$t('she.meeting_trial')" align="center"></el-table-column>
          <el-table-column prop="teamName" :label="$t('she.meeting_teamName')" align="center"></el-table-column>
          <el-table-column prop="leadingUserName" :label="$t('she.meeting_leadingUserName')" align="center"></el-table-column>
          <el-table-column prop="teamSafetyUserName" :label="$t('she.meeting_teamSafetyUserName')" align="center"></el-table-column>
          <el-table-column prop="meetingStartTime" width="130" :label="$t('she.meeting_meetingStartTime')" align="center" sortable="custom"></el-table-column>
          <el-table-column prop="meetingEndTime" :label="$t('she.meeting_meetingEndTime')" align="center"></el-table-column>
          <el-table-column prop="meetingStatus" width="80" :formatter="formatTableText" :label="$t('she.meeting_meetingStatus')" align="center"></el-table-column>
          <el-table-column prop="meetingType" width="80" :formatter="formatTableText" :label="$t('she.meeting_meetingType')" align="center"></el-table-column>
          <el-table-column prop="createTime" :label="$t('cm.create_time')" align="center"></el-table-column>
          <el-table-column :label="$t('cm.operate')" align="center" v-if="isSys ==='false'">
            <template slot-scope="scope">
              <ListBtnSys :options="sysbtns" :is-sys='isSys' :row-data="scope.row" @triggerListBtn="handleListBtn" :show-btn="showBtn"></ListBtnSys>
            </template>
          </el-table-column>
          <el-table-column :label="$t('cm.operate')" align="center" v-if="isSys ==='true'">
            <template slot-scope="scope">
              <ListBtn :options="btns" :row-data="scope.row" @triggerListBtn="handleListBtn" :show-btn="showBtn"></ListBtn>
            </template>
          </el-table-column>
        </el-table>
        <div class="block pager-customer">
          <el-pagination
            background
            layout="total,prev,pager, next,jumper"
            :current-page.sync="pagingCurrentPageNum"
            :page-sizes="pagingPageSizes"
            :page-size="pagingPageSize"
            :total="pagingTotal"
            @size-change="pagingHandleSizeChange"
            @current-change="pagingHandleCurrentChange"
          >
          </el-pagination>
        </div>
      </PageTableCollapse>
    </div>
  </PageTemplate>
</template>
<style lang="scss">
</style>
<script>
import { mapState, mapActions } from 'vuex'
import PageTemplate from '@/components/common/PageTemplate'
import PageTableCollapse from '@/components/common/PageTableCollapse'
import SearchCollapsePro from '@/components/common/SearchCollapsePro'
import ListBtn from '@/components/btn/ListBtn'
import { ALERT } from '@/utils/responseHandle'
import * as Constant from '@/utils/constant'
import {COMMON} from '@/utils/commonUtil'
import Pagination from '@/mixins/Pagination'
import HasBtn from '@/mixins/HasBtn'
import api_she from '@/api/api_she'
import ListBtnSys from '@/components/btn/ListBtnSys'
import { getUserRoles } from '@/api/api.js'
export default {
  components: { PageTemplate, PageTableCollapse, SearchCollapsePro, ListBtn, ListBtnSys },
  data () {
    return {
      query: {
        trial: '',
        orderByFieldList: [3] // 1: meetingStartTime 升序，2：meetingStartTime 降序, 3: createTime: 倒序
      },
      tables:[],
      btns: [
        {
          value: 'edit',
          label: 'cm.edit'
        },
        {
          value: 'info',
          label: 'cm.info'
        }
      ],
      sysbtns: [
        {
          value: 'edit',
          label: 'cm.edit',
          isdba: 'false'
        },
        {
          value: 'info',
          label: 'cm.info',
          isdba: 'true'
        }
      ],
      isSys: '',
    }
  },
  created () {
    this.getAllDataTable()
    this.getNowUserRole()
  },
  mixins: [Pagination, HasBtn],
  watch: {
  },
  methods: {
    ...mapActions('common', [
      'queryCollapse'
    ]),
    getNowUserRole(){
      let _this = this;
      getUserRoles({}).then((result) => {
        if (result.status == "200" && result.data.code == "0") {
      //console.log("==biaozhuan==244===:",result.data.data);
          let dataList = result.data.data
          // sysadmin 系统管理员
          const isAdmin = dataList.some(item => item ==='sysadmin')
          console.log('===isAdmin:',isAdmin)
          if(isAdmin){
            _this.isSys= 'true'
          }else{
            _this.isSys= 'false'
          }
      //console.log("deptNamePath",result.data.data.deptNamePath);
        } else {
          _this.$alert(result.data.msg, _this.$t('cm.tips'));
        }
      }).catch((err) => {
        _this.$alert(err,_this.$t('cm.tips'));
      });
    },
    //重置操作
    queryReset (formName) {
      this.$refs[formName].resetFields()
    },
    queryDataTableLike () {
      this.queryTableList({
        ...this.query,
        pageNum: this.pagingCurrentPageNum,
        pageSize: this.pagingPageSize
      })
    },
    getAllDataTable () {
      this.queryTableList({
        ...this.query,
        pageNum: this.pagingCurrentPageNum,
        pageSize: this.pagingPageSize
      })
    },
    //统一与后台操作的方法
    queryTableList (params) {
      //这里的params是对象
      //注意 如果后台json转对象 时间类型好像会抛异常  转到后台 前台用 qs 来转换数据 设置一个全局拦截器 main.js 参考
      let _this = this
      let tables = []
      let totalCount = 0
      api_she.sheMeetingLoadByPaging(params, result => {
        if (result.code === Constant.RT_SUCCESS) {
          //表格数据  数组
          tables = result.data.results
          //分页数据
          totalCount = result.data.totalRows
        } else {
          // _this.$t('cm.tips')
          ALERT.error(result.data.msg)
        }
        _this.setPagingTotal(totalCount)
        this.tables = tables
      })
    },
    // add () {
    //   COMMON.routerTo(Constant.ROUTE_SHE_MEETING_EDIT.index, this.$router, { id: Constant.NEW_PARAMS })
    // },
    formatTableText (row, column, cellValue, index) {
      //console.log(column.property+'----252----'+cellValue);
      var fmtValue = null
      if (column.property === 'meetingStatus') {
        if(cellValue == 0) {
          fmtValue = "未开始";
        }else if(cellValue == 1){
          fmtValue = "已完成";
        }else if(cellValue == 2){
          fmtValue = "已取消";
        }
      }
      if (column.property === 'meetingType') {
        if(cellValue == 1) {
          fmtValue = "班前会";
        }else if(cellValue == 2){
          fmtValue = "开工会";
        }
      }
      return fmtValue !== null && fmtValue !== undefined ? fmtValue : cellValue
    },
    edit (row) {
      if (row.meetingType === 1) { // 班前会
        COMMON.routerTo(Constant.ROUTE_SHE_TEAMMEETING_EDIT.index, this.$router, { id: row.id })
      } else if (row.meetingType === 2) { // 开工会
        COMMON.routerTo(Constant.ROUTE_SHE_WORKMEETING_EDIT.index, this.$router, { id: row.id })
      }
    },
    edit2 () {
      if (this.multipleSelection.length > 0) {
        var id = this.multipleSelection[0].id;
        COMMON.routerTo(Constant.ROUTE_SHE_MEETING_EDIT.index, this.$router, { id: id })
      }
    },
    editbanqian () {
      COMMON.routerTo(Constant.ROUTE_SHE_TEAMMEETING_EDIT.index, this.$router)
    },
    editgongqian () {
      COMMON.routerTo(Constant.ROUTE_SHE_WORKMEETING_EDIT.index, this.$router)
    },
    del () {
      if (this.multipleSelection.length > 0) {
        COMMON.confirm({}, () => {
          var ids = this.multipleSelection.map(item => item.id)
          this.doDelete(ids)
        })
      } else {
        ALERT.warn('请选择数据')
      }
    },
    doDelete (ids) {
      api_she.sheMeetingDel({ids: ids}, result => {
        if (result.code === Constant.RT_SUCCESS) {
          this.getAllDataTable()
          ALERT.success(result.msg)
        } else {
          ALERT.error(result.msg)
        }
      })
    },
    info (row) { // 编辑专题
      COMMON.routerTo(Constant.ROUTE_SHE_MEETING_INFO.index, this.$router, { id: row.id })
    },
    exportOp() {

    },
    sortMethod ({ column, prop, order }) {
      this.query.orderByFieldList = order === 'descending' ? [2] : [1]
      this.getAllDataTable()
    },
  },
  mounted () {
  },
  computed: {
    ...mapState({
      tableHeaderBGC: state => state.common.tableHeaderBGC
    })
  }
}
</script>
